type User = {
  readonly id: number;
  name: string;
  tel: string;
  address?: string;
}

type Animal = {
  name: string,
  type: "小猫" | "小狗"
}

type UserKeys = keyof User & {};

type CopyUser = {
  [key in keyof User]: User[key]
}

// type A = keyof any;

type Copy<T> = {
  [key in keyof T]: T[key]
}

const user: Copy<User> = {
  id: 1,
  name: "jack",
  tel: "1111",
  address:"cd"
}

const pet: Copy<Animal> = {
  name: "小黑",
  type:"小猫"
}

type MyReadonly<T> = {
  +readonly [key in keyof T]: T[key]
}
// let obj2:Readonly<User> = {}

type MyPartial<T> = {
  [key in keyof T]+?: T[key]
}
// let obj3:Partial<User>
const user2: MyReadonly<User> = {
  id: 2,
  name: "rose",
  tel: "13222222",
  address:"北京"
}
// user2.id = 2;
// user2.name = "john";

const user3: MyPartial<User> = {
  id: 1,
  name:"lily"
}

type MyRequired<T> = {
  -readonly [key in keyof T]-?: T[key]
}

const user4: MyRequired<User> = {
  id: 4,
  name: "lucy",
  tel: "157777777",
  address:"上海"
}
user4.id = 5;

type AnyType = {
  [key: string]: any
}

// function myRecord(key, value) { 
//   // todos...
//   return {key:value}
// }

type MyRecord<Key extends keyof any, Value> = {
  [k in Key]: Value
}
let obj: Record<string, number> = {}